package com.example.demo.web.config;

import com.example.demo.util.ServiceException;
import com.example.demo.vo.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理器
 */
//@ControllerAdvice(basePackages = "com.example.demo.web.controller")
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 所有异常都处理
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultData unKnowException(Exception e){
        log.error("异常：-----> {}",e.getMessage());
        //log.error("异常：-----> "+e.getMessage());
        return ResultData.error("系统未知异常！！！");
    }

    @ExceptionHandler(value = ServiceException.class)
    @ResponseBody
    public ResultData handlerServiceException(ServiceException e){
        log.error("异常：-----> {}",e.getMessage());
        return ResultData.error(e.getMessage());
    }

}
